import time

from selenium.webdriver.common.by import By

from src.main.page.base_page import base_page
from ..utils.Loguru import logger

class Add_member_page(base_page):
    def __init__(self, driver):
        super().__init__(driver)


    def add_member(self):
        logger.info('添加成员')
        _username_input_locate=(By.XPATH,"//*[@id='username']")
        user_input=self.find_ele_is_presence(_username_input_locate)
        _account_iniput_locate=(By.XPATH,"//*[@id='memberAdd_acctid']")
        account_input = self.find_ele_is_presence(_account_iniput_locate)
        # _email_input_locate=(By.XPATH,"//*[@id='memberAdd_mail']")
        # email_input = self.find_ele_is_presence(_email_input_locate)
        _phone_input_locate = (By.XPATH,"//*[@class='qui_inputText ww_inputText ww_telInput_mainNumber']")
        phone_input = self.find_ele_is_presence(_phone_input_locate)
        _save_btn_locate = (By.XPATH,"//*[@class='qui_btn ww_btn js_btn_save']")
        _check_to_invite_locate = (By.XPATH,"//span[contains(text(),'邀请通知')]/../input")
        self.find_ele_is_presence(_check_to_invite_locate).click()
        save_btn = self.find_ele_is_presence(_save_btn_locate)

        phone = self.get_faker_number()
        name = self.get_faker_name()
        account= self.get_faker_account()
        user_input.send_keys(name)
        account_input.send_keys(account)
        phone_input.send_keys(phone)

        self.screen_shot()
        self.download_page_source()

        save_btn.click()
        return name,phone


    def check_input_is_empty(self):
        logger.info('检查必需字段为空时的情况')
        time.sleep(2)
        _username_input_locate = (By.XPATH, "//*[@id='username']")
        user_input = self.find_ele_is_presence(_username_input_locate)
        user_input.click()

        _account_iniput_locate = (By.XPATH, "//*[@id='memberAdd_acctid']")
        account_input = self.find_ele_is_presence(_account_iniput_locate)
        account_input.click()

        _phone_input_locate = (By.XPATH, "//*[@class='qui_inputText ww_inputText ww_telInput_mainNumber']")
        phone_input = self.find_ele_is_presence(_phone_input_locate)
        phone_input.click()

        _check_to_invite_locate = (By.XPATH, "//span[contains(text(),'邀请通知')]/../input")
        self.find_ele_is_presence(_check_to_invite_locate).click()

        _name_empty_warm_locate=(By.XPATH,"//*[@class='ww_compatibleTxt ww_compatibleTxt_Small ww_inputWithTips_WithErr']/div")
        name_warm_text = self.find_ele_is_presence(_name_empty_warm_locate).text
        _account_empty_warm_locate=(By.XPATH,"//*[@class='member_edit_item_right ww_inputWithTips_WithErr']/div")
        account_warm_text = self.find_ele_is_presence(_account_empty_warm_locate).text
        _phton_empty_warm_locate=(By.XPATH,"//label[text()='手机：']/..//*[@class='ww_inputWithTips_tips']")
        phone_warm_text = self.find_ele_is_presence(_phton_empty_warm_locate).text

        if(name_warm_text!=''):
            logger.debug('用户名不能为空')
        if (account_warm_text != ''):
            logger.debug('账号不能为空')
        if (phone_warm_text != ''):
            logger.debug('电话不能为空')





